package cn.stylefeng.guns.sys.modular.dict.controller;

import cn.stylefeng.guns.core.context.login.LoginContextHolder;
import cn.stylefeng.guns.core.pojo.login.SysLoginUser;
import cn.stylefeng.guns.core.pojo.response.ResponseData;
import cn.stylefeng.guns.sys.modular.dict.result.DictDTO;
import cn.stylefeng.guns.sys.modular.dict.result.DictDetail;
import cn.stylefeng.guns.sys.modular.dict.service.SysDictTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description:
 * @Author jzy
 * @Date 2020/9/25 0025
 **/
@Api(tags = "系统管理：字典管理")
@RestController
@RequestMapping("/api/dict")
public class DictController {

    @Resource
    private SysDictTypeService dictService;


    @GetMapping("/detail")
    @ApiOperation(value = "字典详情")
    public ResponseData getDictDetail(DictDTO dict) {
        //获取当前登录人的租户id
        /**
         * 获取租户号
         * @return
         */
        Long tenantId = null;
        if (LoginContextHolder.me().isSuperAdmin()) {
            tenantId = 1l;
        } else {
            SysLoginUser loginUser = LoginContextHolder.me().getSysLoginUser();
            tenantId = loginUser.getTenantId();
        }
        List<DictDetail> list = dictService.getDictDetailList(dict, tenantId);
        return ResponseData.andaSuccess(list);
    }


}
